//
//  ZJScheduleView.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/3.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJScheduleView.h"

@interface ZJScheduleView ()
/** 完成的view */
@property (nonatomic, strong) UIView *complete;

/** titleLbale */
@property (nonatomic, strong) UILabel *label;
@end

@implementation ZJScheduleView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor viewBGGrayColor];
        [self addSubview: self.complete];
        [self addSubview:self.label];
        self.label.sd_layout
        .topEqualToView(self)
        .leftEqualToView(self)
        .rightEqualToView(self)
        .bottomEqualToView(self);
    }
    return self;
}


#pragma mark - Setter
- (void)setPercentage:(NSString *)percentage{
    _percentage = percentage;
    
    
    NSString * number = [percentage substringToIndex:percentage.length -1];
    if ([number floatValue] > 100) {
        number = @"100";
    }
    self.label.text = [NSString stringWithFormat:@"%@%%", number];
    self.complete.sd_layout
    .topSpaceToView(self, 0)
    .leftSpaceToView(self, 0)
    .bottomSpaceToView(self, 0)
    .widthRatioToView(self, [number floatValue] / 100.0);
    [self.complete updateLayout];
}

#pragma mark - Getters
- (UIView *)complete{
    if (_complete == nil){
        _complete = [UIView new];
        _complete.backgroundColor = [UIColor zj_colorWithHexString:@"5bb85b"];
    }
    return _complete;
}

- (UILabel *)label{
    if (_label == nil){
        _label = [[UILabel alloc] init];
        _label.textColor = [UIColor zj_colorWithHexString:@"4b4c4b"];
        _label.font = [UIFont systemFontOfSize: 12 * [UIScreen zj_textFontScale]];
        _label.textAlignment = NSTextAlignmentRight;
    }
    return _label;
}

@end
